package com.coffee.wakeonlan.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.coffee.wakeonlan.dao.MachineDao;
import com.coffee.wakeonlan.dao.UserDao;
import com.coffee.wakeonlan.entity.Machine;
import com.coffee.wakeonlan.entity.User;

@Service
@Transactional(readOnly=false)
public class MachineService {
	@Autowired
	private MachineDao machineDao;
	@Autowired
	private UserDao userDao;
	
	public Machine get(Long id){
		return machineDao.findOne(id);
	}
	public void add(Machine machine){
		machineDao.save(machine);
	}
	public void delete(Machine machine){
		machineDao.delete(machine);
	}
	
	public Machine findByMac(String mac){
		return machineDao.findByMac(mac);
	}
	public List<Machine> findByUserId(Long userId){
		return machineDao.findByUserId(userId);
	}
	public void offlineAll(){
		machineDao.offlineAll();
	}
	public List<Machine> findByMacs(List<String> macs){
		return machineDao.findByMacs(macs);
	}
	public User findByLoginName(String loginName){
		return userDao.findByLoginName(loginName);
	}
}
